//
//  CallInViewController.m
//  HollyPhoneSdk
//
//  Created by hollycrm on 2022/8/11.
//

#import "CallInViewController.h"
#import "Wrapper.h"
#import "AudioManager.h"
#import "HollyPhoneManager.h"
#import "HollyPhoneProtocol.h"

@interface CallInViewController ()
@property (strong, nonatomic) NSBundle * bundle;
@property (weak, nonatomic) IBOutlet UIView *waitingView;
@property (weak, nonatomic) IBOutlet UIImageView *logoImg;
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UIButton *muteBt;
@property (weak, nonatomic) IBOutlet UIButton *speakerBt;

@end

@implementation CallInViewController
- (IBAction)refuseClick:(id)sender {
    [[CPPWrapper new] hangupCallWrapper];
    [self dismissViewControllerAnimated:true completion:nil];
}
- (IBAction)acceptClick:(id)sender {
    [[CPPWrapper new] answerCallWrapper];
    _waitingView.hidden = true;
}
- (IBAction)hangUpClick:(id)sender {
    [[CPPWrapper new] hangupCallWrapper];
    [self dismissViewControllerAnimated:true completion:nil];
}
- (IBAction)muteClick:(id)sender {
    if ([AudioManager shared]._isMicOn){
        [[AudioManager shared] closeMic];
        NSString *file1 = [_bundle pathForResource:@"mute_select" ofType:@"png"];
        UIImage *image1 = [UIImage imageWithContentsOfFile:file1];
        [_muteBt setImage:image1 forState:UIControlStateNormal];
    }
    else{
        [[AudioManager shared] openMic];
        NSString *file2 = [_bundle pathForResource:@"mute_normal" ofType:@"png"];
        UIImage *image2 = [UIImage imageWithContentsOfFile:file2];
        [_muteBt setImage:image2 forState:UIControlStateNormal];
    }
}
- (IBAction)speakerClick:(id)sender {
    if([AudioManager shared]._isSpeakerOn){
        [[AudioManager shared] setSpeakerOff];
        NSString *file1 = [_bundle pathForResource:@"speak_normal" ofType:@"png"];
        UIImage *image1 = [UIImage imageWithContentsOfFile:file1];
        [_speakerBt setImage:image1 forState:UIControlStateNormal];
        
    }
    else{
        [[AudioManager shared] setSpeakerOn];
        NSString *file2 = [_bundle pathForResource:@"speak_select" ofType:@"png"];
        UIImage *image2 = [UIImage imageWithContentsOfFile:file2];
        [_speakerBt setImage:image2 forState:UIControlStateNormal];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    _label1.text = _callId;
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
   
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [[CPPWrapper new] hangupCallWrapper];
}

-(instancetype)init{
   //pod 版本地址路径
//       _bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle].bundlePath stringByAppendingPathComponent:@"HollyPhone.bundle"]];
//          self = [super initWithNibName:@"CallInViewController" bundle:bundle];
//          return self;

   //手动集成路径
    _bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle].bundlePath stringByAppendingPathComponent:@"/Frameworks/HollyPhoneSdk.framework/HollyPhone.bundle"]];

       self = [super initWithNibName:@"CallInViewController" bundle:_bundle];

       return self;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
